<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of notification
 *
 * @author TimotiusNC
 */
class NotificationController extends Controller {
    protected $allowed = array('administrator' , 'member');


    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $notifications = Model::loadRowsFromQuery("SELECT * FROM `notification` WHERE user_id = ".$this->auth->id." ORDER BY `id` DESC;", 'NotificationModel');
        foreach ($notifications as $n) {
            if ($n->status == NotificationModel::$NOTIF_UNREAD) {
                $n->status = NotificationModel::$NOTIF_READ;
                $n->save();
            }
        }

        if ($this->isAllowed())
            $this->render("notification/index", array('notifications' => $notifications));
        else
            $this->showError('You are not allowed to open this page');
    }
}
?>
